package by.koleda.benicetobunnies;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class ResultActivity extends Activity {

	private ImageView resultView;
	private TextView companyName;
	private TextView resultText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		setContentView(R.layout.activity_result);

		resultView = (ImageView) findViewById(R.id.imageview_scan_result);
		companyName = (TextView) findViewById(R.id.company_name_view);
		resultText = (TextView) findViewById(R.id.test_result_view);

		Intent intent = this.getIntent();
		int result = intent.getIntExtra(MainActivity.EXTRA_RESULT_MESSAGE, 0);
		String name = intent.getStringExtra(MainActivity.EXTRA_COMPANY_MESSAGE);

		switch (result) {
		case 0: {
			resultView.setImageResource(R.drawable.bunny_blue);
			companyName.setText(R.string.empty);
			companyName.setTextColor(getResources().getColor(R.color.bunny_blue));
			resultText.setText(R.string.not_found);
			resultText.setTextColor(getResources().getColor(R.color.bunny_blue));
			break;
		}
		case 1: {
			resultView.setImageResource(R.drawable.bunny_red);
			companyName.setText(name);
			companyName.setTextColor(getResources().getColor(R.color.bunny_red));
			resultText.setText(R.string.does_test);
			resultText.setTextColor(getResources().getColor(R.color.bunny_red));
			break;
		}
		case 2: {
			resultView.setImageResource(R.drawable.bunny_green);
			companyName.setText(name);
			companyName.setTextColor(getResources().getColor(R.color.bunny_green));
			resultText.setText(R.string.does_not_test);
			resultText.setTextColor(getResources().getColor(R.color.bunny_green));
			break;
		}
		default: {
			resultView.setImageResource(R.drawable.bunny_blue);
			companyName.setText(R.string.empty);
			companyName.setTextColor(getResources().getColor(R.color.bunny_blue));
			resultText.setText(R.string.not_found);
			resultText.setTextColor(getResources().getColor(R.color.bunny_blue));
		}
		}
	}

	public void onScanAgainClick(View view) {
		Intent answerIntent = new Intent();
		setResult(RESULT_OK, answerIntent);
		finish();
	}

}
